﻿using System;
using System.Diagnostics;
using System.Threading;
using HtmlAgilityPack;

namespace SecurityModule
{
    static class TfsVersionChecker
    {
        private const string CodeplexUri = "https://secmod4salestax.codeplex.com";
        private const int MaxRetries = 5;

        internal static string GetLatestChangesetId()
        {
            for (var retry = 0; retry < MaxRetries; retry++)
            {
                try
                {
                    var doc = new HtmlWeb().Load(string.Format("{0}/SourceControl/list/changesets", CodeplexUri));
                    var nodes = doc.DocumentNode.SelectNodes("//a[@id='ChangeSetLink0']");
                    return nodes[0].InnerText;
                }
                catch (Exception exp)
                {
                    EventLog.WriteEntry("SecModule", "GetLatestChangesetId Failed: " + exp.Message, EventLogEntryType.Error);
                    Thread.Sleep(100);
                }
            }
            return "";
        }
    }
}
